import pytest
import os
import time

from ReadConfigFile import ReadConfigFile
from SendingEmails import SendingEmails
from pytest_main import PytestMain

if __name__ == '__main__':


    # 读取配置文件
    read_config = ReadConfigFile('config.ini')
    client = PytestMain(
        read_config.read_config_file("pytest_main", "ip"),
        int(read_config.read_config_file("pytest_main", "port")),
        read_config.read_config_file("pytest_main", "username"),
        read_config.read_config_file("pytest_main", "password")
    )
    send_email = SendingEmails(read_config.read_config_file('sending_emails', 'from_addr'),
                               read_config.read_config_file('sending_emails', 'to_addr'),
                               read_config.read_config_file('sending_emails', 'smtp_server'),
                               read_config.read_config_file('sending_emails', 'smtp_port'),
                               read_config.read_config_file('sending_emails', 'password')
                               )
    # client.remove_file("huanaoao")
    time.sleep(3)
    pytest.main(['D:\Python\Project\project01\Auto\day02','-sv','--alluredir','././report/temp_jsonreport'])
    os.system("allure generate ./report/temp_jsonreport -o ./report/huanaoao --clean")  # 使用Allure命令行工具生成HTML格式的报告
    time.sleep(10)
    client.upload_file_path('./report/huanaoao', '/usr/local/nginx/html')
    time.sleep(10)
    # client.remove_file("huanaoao")
    subject = "测试邮件"
    content = """
        <html>
        <body>
            <h2>

                <a href="http://192.168.10.100:80/huanaoao">测试用例已执行，请点击查看测试报告</a>
            </h2>
        </body>
        </html>
        """
    send_email.send_html_email(subject, content)
